package com.ruoyi.system.controller;

import java.util.List;
import javax.annotation.Resource;

import com.ruoyi.system.domain.dto.EnterpriseSupplierByIdsDTO;
import com.ruoyi.system.domain.dto.EnterpriseSupplierDTO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.EnterpriseSupplier;
import com.ruoyi.system.service.IEnterpriseSupplierService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业对应合作商关系Controller
 *
 * @author 协同
 * @date 2022-04-18
 */
@RestController
@RequestMapping("/system/supplier")
public class EnterpriseSupplierController extends BaseController {
    @Resource
    private IEnterpriseSupplierService enterpriseSupplierService;

    /**
     * 查询企业对应合作商关系列表
     */
    @GetMapping("/list")
    public TableDataInfo list(EnterpriseSupplierDTO enterpriseSupplierDTO) {
        startPage();
        List<EnterpriseSupplier> list = enterpriseSupplierService.selectEnterpriseSupplierList(enterpriseSupplierDTO);
        return getDataTable(list);
    }

    /**
     * 获取企业对应合作商关系详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(enterpriseSupplierService.selectEnterpriseSupplierById(id));
    }

    /**
     * 新增企业对应合作商关系
     */
    @PostMapping
    public AjaxResult add(@RequestBody EnterpriseSupplierDTO enterpriseSupplierDTO) {
        return AjaxResult.success(enterpriseSupplierService.insertEnterpriseSupplier(enterpriseSupplierDTO));
    }

    /**
     * 修改企业对应合作商关系
     */
    @PutMapping
    public AjaxResult edit(@RequestBody EnterpriseSupplier enterpriseSupplier) {
        return toAjax(enterpriseSupplierService.updateEnterpriseSupplier(enterpriseSupplier));
    }

    /**
     * 停止企业对应合作商关系
     */
    @PostMapping("/updateByIds")
    public AjaxResult updateByIds(@RequestBody EnterpriseSupplierByIdsDTO dto) {
        return toAjax(enterpriseSupplierService.updateByIds(dto.getIds().toArray(new Long[0])));
    }

    /**
     * 删除企业对应合作商关系
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(enterpriseSupplierService.deleteEnterpriseSupplierByIds(ids));
    }
}
